package com.prs.crm.action.sys;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;

import com.prs.crm.domain.sys.DefaultDesktopSet;
import com.prs.crm.domain.sys.DesktopSet;
import com.prs.crm.service.sys.DefaultDesktopSetService;
import com.prs.crm.service.sys.DesktopSetService;

public class DefaultDesktopSetAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private DefaultDesktopSet defaultDesktopSet;
	private DefaultDesktopSetService defaultDesktopSetService;
	private List<DesktopSet> desktopSet;
	private DesktopSetService desktopSetService;
	private String serCode;
	private List<DesktopSet> deskTopSets;
	private List<DesktopSet> updateDesktopSets;	
	public List<DesktopSet> getUpdateDesktopSets() {
		return updateDesktopSets;
	}
	public void setUpdateDesktopSets(List<DesktopSet> updateDesktopSets) {
		this.updateDesktopSets = updateDesktopSets;
	}
	public List<DesktopSet> getDeskTopSets() {
		return deskTopSets;
	}
	public void setDeskTopSets(List<DesktopSet> deskTopSets) {
		this.deskTopSets = deskTopSets;
	}
	public String getSerCode() {
		return serCode;
	}
	public void setSerCode(String serCode) {
		this.serCode = serCode;
	}
	public List<DesktopSet> getDesktopSet() {
		return desktopSet;
	}
	public void setDesktopSet(List<DesktopSet> desktopSet) {
		this.desktopSet = desktopSet;
	}
	public DesktopSetService getDesktopSetService() {
		return desktopSetService;
	}
	public void setDesktopSetService(DesktopSetService desktopSetService) {
		this.desktopSetService = desktopSetService;
	}
	public DefaultDesktopSet getDefaultDesktopSet() {
		return defaultDesktopSet;
	}
	public void setDefaultDesktopSet(DefaultDesktopSet defaultDesktopSet) {
		this.defaultDesktopSet = defaultDesktopSet;
	}
	public DefaultDesktopSetService getDefaultDesktopSetService() {
		return defaultDesktopSetService;
	}
	public void setDefaultDesktopSetService(
			DefaultDesktopSetService defaultDesktopSetService) {
		this.defaultDesktopSetService = defaultDesktopSetService;
	}
	
	@Action("editDefaultDesktopSet")
	public String editDefaultDesktopSet(){
		this.desktopSet=this.getDesktopSetService().getAllDesktopSet();
//		this.deskTopSets=this.getDesktopSetService().getAllDesktopSet();
//		this.updateDesktopSets=this.getDesktopSetService().getAllDesktopSet();
		this.defaultDesktopSet=this.getDefaultDesktopSetService().getDefaultDesktopSet(serCode);
		return SUCCESS;
	}
	
	@Action(value="saveDefaultDesktopSet",results={
			@Result(name="success",type="redirect",location="editDefaultDesktopSet?serCode=${defaultDesktopSet.getInserCode()}"),
			@Result(name="error",type="chain",location="editDefaultDesktopSet?serCode=${defaultDesktopSet.getInserCode}")
	})
	public String saveDefaultDesktopSet(){
		DefaultDesktopSet ds=this.getDefaultDesktopSetService().getDefaultDesktopSet("ds01");
		if (ds==null) {
			ds=new DefaultDesktopSet();
			ds.setInserCode("ds01");
			ds.setType(defaultDesktopSet.getType());
			ds.setUserAll(defaultDesktopSet.getUserAll());
			ds.setUserDefineDesk(defaultDesktopSet.getUserDefineDesk());
			this.getDefaultDesktopSetService().save(ds);
		}else{
			this.getDefaultDesktopSetService().submit(ds);
		}
		defaultDesktopSet=ds;
		return SUCCESS;
	}
}
